Skip to content

Disable color for formatter file output#1886

Open
StantonMatt wants to merge 1 commit into
cucumber:mainfrom
StantonMatt:fix-file-formatter-color
Open

Disable color for formatter file output#1886
StantonMatt wants to merge 1 commit into
cucumber:mainfrom
StantonMatt:fix-file-formatter-color

Conversation

@StantonMatt

Copy link
Copy Markdown
Contributor

Description

Addresses the default formatter-output behavior from #1288.

Console formatters now decide default coloring from their own output stream. That means a command like --format pretty --out pretty.txt --format progress can keep the progress formatter colored on a TTY while writing plain text to pretty.txt.

Explicit --color and --no-color still override the output destination.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • Tests have been added for any changes to behaviour of the code
  • bundle exec rubocop reports no offenses
  • CHANGELOG.md has been updated

Checked locally:

  • bundle exec rspec
  • bundle exec cucumber --publish-quiet
  • bundle exec rspec spec/cucumber/formatter/console_spec.rb spec/cucumber/formatter/console_counts_spec.rb spec/cucumber/cli/configuration_spec.rb
  • bundle exec rspec compatibility/spec -f d
  • bundle exec rubocop

@StantonMatt StantonMatt force-pushed the fix-file-formatter-color branch from 3ea5cde to b074398 Compare June 3, 2026 17:16
Signed-off-by: Matthew Stanton <stantonmatthewj@gmail.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates console formatter coloring so default ANSI color behavior is determined per-formatter from its own output stream (TTY vs --out file), while still honoring explicit --color / --no-color.

Changes:

  • Added per-formatter color decision logic in Console via a scoped with_formatter_coloring wrapper.
  • Persisted CLI --[no-]color into parsed options so formatter instances can detect explicit overrides.
  • Added specs and changelog entry covering the new default behavior for --out.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
spec/cucumber/formatter/console_spec.rb Adds coverage for default/per-output coloring behavior and step-arg formatting.
lib/cucumber/formatter/console.rb Scopes global ANSIColor state to a formatter call based on destination and explicit options.
lib/cucumber/formatter/console_counts.rb Stores @config so Console coloring logic can inspect formatter output/options.
lib/cucumber/cli/options.rb Saves parsed --[no-]color into @options[:color] in addition to setting global state.
CHANGELOG.md Documents the new default: no ANSI color when console output is written via --out.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +35 to +40
it 'uses color by default when the formatter output is a tty' do
@io = instance_double(IO, tty?: true)
@options = {}

expect(format_string('undefined', :undefined)).to include("\e[33m")
end
Comment on lines +49 to +54
it 'allows explicit color to override the formatter output destination' do
@io = instance_double(File, tty?: false)
@options = { color: true }

expect(format_string('undefined', :undefined)).to include("\e[33m")
end
Comment on lines +236 to +242
def with_formatter_coloring
original_coloring = Cucumber::Term::ANSIColor.coloring?
Cucumber::Term::ANSIColor.coloring = formatter_coloring?
yield
ensure
Cucumber::Term::ANSIColor.coloring = original_coloring
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants